home *** CD-ROM | disk | FTP | other *** search
/ Aminet 18 / aminetcdnumber181997.iso / Aminet / dev / amos / AMOSList_0197.lzh / AMOSLIST / 000167_amos-request@svcs1.digex.net_Wed Jan 29 18:58:33 1997.msg < prev    next >
Internet Message Format  |  1997-02-02  |  3KB

  1. Received: from svcs1.digex.net (svcs1.digex.net [204.91.197.224])
  2.     by mail1.access.digex.net (8.8.5/8.8.5) with ESMTP id SAA21802
  3.     for <mcox@access.digex.net>; Wed, 29 Jan 1997 18:57:55 -0500 (EST)
  4. Received: (from daemon@localhost)
  5.     by svcs1.digex.net (8.8.5/8.8.5) id OAA09538
  6.     for amos-out; Wed, 29 Jan 1997 14:59:49 -0500 (EST)
  7. Received: from mail2.access.digex.net (mail2.access.digex.net [205.197.247.3])
  8.     by svcs1.digex.net (8.8.5/8.8.5) with ESMTP id OAA09531
  9.     for <amos-list@svcs1.digex.net>; Wed, 29 Jan 1997 14:59:47 -0500 (EST)
  10. Received: from hermes.beotel.net (ns.beotel.net [194.106.162.2])
  11.     by mail2.access.digex.net (8.8.5/8.8.5) with ESMTP id OAA17067
  12.     for <amos-list@access.digex.net>; Wed, 29 Jan 1997 14:59:44 -0500 (EST)
  13. Received: from setnet.UUCP (Usetnet@localhost) by hermes.beotel.net (8.7.6/8.6.12) with UUCP id UAA17400 for amos-list@access.digex.net; Wed, 29 Jan 1997 20:37:22 +0100
  14. X-Authentication-Warning: hermes.beotel.net: Usetnet set sender to setnet!smolenski using -f
  15. Received: by setnet.co.yu (0.99.960714)
  16.   id AA02946; 28 Jan 97 14:51:31 +0100
  17. From: smolenski@setnet.co.yu (Nikola Smolenski)
  18. Date: 28 Jan 97 14:48:05 +0100
  19. Subject: goto
  20. Message-ID: <b44_9701281451@setnet.co.yu>
  21. Organization: SETNet - Ujedinjeni BBS-ovi Balkana
  22. To: amos-list@access.digex.net
  23. Status: RO
  24. X-Status: 
  25.  
  26.  
  27. >  gs> How can I get the program to go to each label
  28. >  gs> only once?  (randomly)
  29.  
  30. > I think this is the easiest:
  31. > dim a(n)
  32. > for i=1 to n
  33. > a(i)=i
  34. > next
  35. > for i=1 to n
  36. > r=rnd(n)+1
  37. > goto r
  38. > a(r)=a(n)
  39. > dec n
  40. > next
  41.  
  42.  bu> I can't follow the logic of that program, but this program will do what
  43.  bu> was originally requested:
  44.  
  45.  bu> Dim a(4)
  46.  
  47.  bu> ' Store the label numbers in an array
  48.  bu> For n=0 To 4
  49.  bu> a(n)=n
  50.  bu> Next n
  51.  
  52.  bu> ' Shuffle the array about, 25 times
  53.  bu> For time=1 To 25
  54.  bu> Swap a(Rnd(4)),a(Rnd(4))
  55.  bu> Next time
  56.  
  57. Yes, I like it the most:) Maybe it is a bit slower, but nothing serious. 
  58. However, here is explanation:
  59.  
  60. dim a(n)
  61. for i=1 to n
  62. a(i)=i
  63. next
  64. 'all clear till now
  65. for i=1 to n
  66. 'will do it n times
  67. r=rnd(n)+1
  68. goto r
  69. 'goto randomly choosen line, from n possible, n is at start size of a()
  70. a(r)=a(n)
  71. 'last number in a() replaces used number
  72. dec n
  73. 'n is decreased ('cause last number is moved) 
  74. next
  75.  
  76. And now I got that it could be done with rnd (0) :
  77.  
  78. for i=1 to n
  79. goto rnd (n)+1
  80. a(rnd(0))=a(n)
  81. dec n
  82. next
  83.  
  84. And this have even less code (and SHOULD work:):
  85.  
  86. 'v 1.2 :)
  87. for i=n to 1 step -1
  88. goto rnd (i)+1
  89. a(rnd(0))=a(i)
  90. next
  91. _        _  _         _  _          _                                   _
  92. \--- :_ :_ :_::- --: : ::_) _: --- \/ ----------------------------------/
  93. \\_: !_)!_,! !!_,  !,!_!! \(_! ::::..::::      nEVERmIND     :::'`::::_//
  94. `\------------------------------------------------------------- /\ ----/'
  95.   Nikola Smolenski - member of Team AMIGA        smolenski@setnet.co.yu
  96.  
  97.  * *** NOVI SAAAAAAAAAD!!!!!!!!!!!!!!!!!!!!!!!!! *** *
  98.  
  99.  * AmyBW v2.14 *
  100. ... Bilo mi je lepo u materici, zato stalno idem sto dublje mogu ka njoj!
  101. --- Blue Wave/RA